package com.lineage.data.event.gambling;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Random;

public class Gambling extends GamblingConfig {
  private final Map<Integer, GamblingNpc> _npcidMap = new HashMap<>();
  
  private final Random _random = new Random();
  
  public int WIN;
  
  private GamblingNpc _onenpc;
  
  private long _adena;
  
  private long _upadena;
  
  public void clear() {
    this._npcidMap.clear();
    this._onenpc = null;
    this._adena = 0L;
  }
  
  public long get_allAdena() {
    return this._adena;
  }
  
  public void set_gmaNpc(long previous) {
    if (GamblingConfig.ISGFX) {
      GamblingConfig.ISGFX = false;
    } else {
      GamblingConfig.ISGFX = true;
    } 
    this.WIN = this._random.nextInt(5);
    int i = 0;
    while (this._npcidMap.size() < 5) {
      int npcid = GamblingConfig.NPCID[this._random.nextInt(GamblingConfig.NPCID.length)];
      if (this._npcidMap.get(new Integer(npcid)) == null) {
        GamblingNpc gamnpc = new GamblingNpc(this);
        gamnpc.showNpc(npcid, i++);
        this._npcidMap.put(new Integer(npcid), gamnpc);
      } 
    } 
    this._upadena = previous;
  }
  
  public long get_allRate() {
    long adena = 0L;
    Iterator<GamblingNpc> iterator = this._npcidMap.values().iterator();
    while (iterator.hasNext()) {
      GamblingNpc gamblingNpc = iterator.next();
      adena += gamblingNpc.get_adena();
    } 
    return adena + this._upadena;
  }
  
  public void set_allRate() {
    long adena = this._upadena;
    Iterator<GamblingNpc> iterator = this._npcidMap.values().iterator();
    while (iterator.hasNext()) {
      GamblingNpc gamblingNpc = iterator.next();
      adena += gamblingNpc.get_adena();
    } 
    this._adena = adena;
    Iterator<GamblingNpc> iterator2 = this._npcidMap.values().iterator();
    while (iterator2.hasNext()) {
      GamblingNpc gamblingNpc = iterator2.next();
      set_npcRate(gamblingNpc, adena);
    } 
  }
  
  private void set_npcRate(GamblingNpc npc, long adena) {
    double rate = (10 + this._random.nextInt(20));
    npc.set_rate(rate / 10.0D);
  }
  
  public Map<Integer, GamblingNpc> get_allNpc() {
    return this._npcidMap;
  }
  
  public GamblingNpc get_oneNpc() {
    return this._onenpc;
  }
  
  public void set_oneNpc(GamblingNpc onenpc) {
    this._onenpc = onenpc;
  }
  
  public void startGam() {
    Iterator<GamblingNpc> iterator = this._npcidMap.values().iterator();
    while (iterator.hasNext()) {
      GamblingNpc gamblingNpc = iterator.next();
      gamblingNpc.getStart();
    } 
  }
  
  public void delAllNpc() {
    Iterator<GamblingNpc> iterator = this._npcidMap.values().iterator();
    while (iterator.hasNext()) {
      GamblingNpc gamblingNpc = iterator.next();
      gamblingNpc.delNpc();
    } 
  }
}
